import React, { Suspense } from 'react'
import getContact from "@/ssr/getContact";
import BlogLayout from '@/components/client/blogs/BlogLayout'
import getBlogBySlug from "@/ssr/getBlogBySlug";
import getBlogs from "@/ssr/getBlogs";

export async function generateMetadata({params}) {
  const contact = await getContact();
  const {slug} = await params;
  const blog = await getBlogBySlug(slug);
  return {
    title: blog.meta_title ? blog.meta_title : `${blog.title} | ${contact.meta_title || contact.name}`,
    description: blog.meta_description ? blog.meta_description : `${contact.meta_description || contact.description}`,
  };
}

export default async function Blogs() {
  const blogsData = await getBlogs();
  let blogs = blogsData.blogs;
  blogs.unshift({title: '全部', slug: 'all', id: 0, template:'default', status: 0});
  return (
    <Suspense fallback={<div>加载中...</div>}>
      <BlogLayout blogs={blogs}/>
    </Suspense>
  )
}
